import React, { Component } from 'react'


class Cpn extends Component {
  render() {
    return (
      <div>
        <h2>我是Cpn组件</h2>
      </div>
    )
  }


  componentWillUnmount() {
    console.log("调用了Cpn的 componentWillUnmount 方法");
  }
}


export default class App extends Component {

  constructor() {
    super();

    this.state = {
      count: 0,
      isShow: true
    }

    console.log("执行了组件的 constructor 方法");
  }

  render() {
    console.log("执行了组件的 render 方法");
    return (
      <div>
        App组件
        <h2>当前计数：{this.state.count}</h2>
        <button onClick={() => this.incrementCount()}>+1</button>
        <hr />
        <button onClick={() => this.changeCpn()}>切换</button>
        {this.state.isShow && <Cpn></Cpn>}
      </div>
    )
  }

  changeCpn() {
    this.setState({
      isShow: !this.state.isShow
    })
  }

  incrementCount() {
    this.setState({
      count: this.state.count + 1
    })
  }

  componentDidMount() {
    console.log("执行了组件的 componentDidMount 方法");
  }

  componentDidUpdate(prevProps, prevState, snapshot) {
    console.log("执行了组件的 componentDidUpdate 方法");

  }
}
